//
//  HZGoodsDetailHeadView.m
//  app
//
//  Created by 刘华舟 on 15/5/26.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HZGoodsDetailHeadView.h"


@interface HZGoodsDetailHeadView()

@property (strong, nonatomic) UILabel* titleLabel;
@property (strong, nonatomic) UILabel* serviceLabel;

@property (strong, nonatomic) UILabel* gfzpLabel;
@property (strong, nonatomic) UILabel* sdfhLabel;
@property (strong, nonatomic) UILabel* wythLabel;


@end


@implementation HZGoodsDetailHeadView

- (void)drawRect:(CGRect)rect{
    
    [self drawBackground:self.bounds color:HZ_MALL_MAIN_THEME_WHITE];
    [self drawHorizonLineLeft:[self.ubo uw:0] right:[self.ubo uw:0] at:[self.ubo fh:UB_TOP ph:floor(1)] color:HZ_MALL_M_SEPARATOR_CELL_LINE];
    
    [self drawSingleLineFromPoint:[UBO_WINDOW.ubo fx:UB_WIDTH/3.0f oy:kHZGoodsDetailLabelHeight*2] toPoint:[UBO_WINDOW.ubo fx:UB_WIDTH/3.0f oy:kHZGoodsDetailLabelHeight*3] color:HZ_MALL_M_SEPARATOR_CELL_LINE];
    
    [self drawSingleLineFromPoint:[UBO_WINDOW.ubo fx:UB_WIDTH*2/3.0f oy:kHZGoodsDetailLabelHeight*2] toPoint:[UBO_WINDOW.ubo fx:UB_WIDTH*2/3.0f oy:kHZGoodsDetailLabelHeight*3] color:HZ_MALL_M_SEPARATOR_CELL_LINE];
    
    [self drawHorizonLineLeft:[self.ubo uw:0] right:[self.ubo uw:0] at:[self.ubo fh:UB_BOTTOM ph:-floor(1)] color:HZ_MALL_M_SEPARATOR_CELL_LINE];
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = HZ_MALL_S_LIGHT_GRAY_BACKGROUND_COLOR;
        self.contentMode = UIViewContentModeRedraw;
        
        self.frame = CGRectOf(frame.origin, [UBO_WINDOW.ubo fw:UB_WIDTH oh:kHZGoodsDetailHeadViewHeight]);
        
        //商品详情
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectOf([self.ubo fx:UB_LEFT ux:kSizeMallViewMargin fy:UB_TOP oy:kHZGoodsDetailLabelHeight/3],
                                                                 [self.ubo fw:UB_HALF uw:-kSizeMallViewMargin oh:kHZGoodsDetailLabelHeight])];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.textColor = HZ_MALL_TEXT_M_LIGHTGRAY_COLOR;
        _titleLabel.font = kHZFont_Content_S;
        _titleLabel.text = @"商品详情";
        [self addSubview:_titleLabel];
        
        //联系客服
        _serviceLabel = [[UILabel alloc] initWithFrame:CGRectOf([self.ubo fx:UB_CENTER fy:UB_TOP oy:kHZGoodsDetailLabelHeight/3],
                                                              [self.ubo fw:UB_HALF uw:-kSizeMallViewMargin oh:kHZGoodsDetailLabelHeight])];
        _serviceLabel.textAlignment = NSTextAlignmentRight;
        _serviceLabel.textColor = HZ_MALL_MAIN_THEME_M_BLUE;
        _serviceLabel.font = kHZFont_Content_S;
        _serviceLabel.text = @"联系客服";
        [self addSubview:_serviceLabel];
        
        
        UITapGestureRecognizer *tapGester = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(connectProductDetailsService)];
        _serviceLabel.userInteractionEnabled = YES;
        [_serviceLabel addGestureRecognizer:tapGester];
        
        //官方正品
        _gfzpLabel = [[UILabel alloc] initWithFrame:CGRectOf([self.ubo fx:UB_LEFT fy:UB_TOP oy:kHZGoodsDetailLabelHeight*2],
                                                                [self.ubo fw:UB_WIDTH/3.0f oh:kHZGoodsDetailLabelHeight])];
        _gfzpLabel.textAlignment = NSTextAlignmentCenter;

        [self addSubview:_gfzpLabel];

        NSString *originStrG = @" 官方正品";
        NSTextAttachment *textAttachmentG = [[NSTextAttachment alloc] init];
        textAttachmentG.image = [UIImage imageNamed:kImageDeliveryGuan];  //设置图片源
            textAttachmentG.bounds = CGRectOf([self.gfzpLabel.ubo fx:UB_LEFT fy:UB_TOP py:-8],
                                             [self.gfzpLabel.ubo ow:15 oh:16]);          //设置图片位置和大小
        NSAttributedString *attrStrAttG = [NSAttributedString attributedStringWithAttachment:textAttachmentG];
        
        
        NSMutableAttributedString *attrStrG = [[NSMutableAttributedString alloc] initWithString:originStrG];
        
        [attrStrG addAttribute:NSFontAttributeName value:kHZFont_Tag_M range: NSMakeRange(0, originStrG.length)];
        [attrStrG addAttribute:NSForegroundColorAttributeName value:HZ_MALL_TEXT_M_LIGHTGRAY_COLOR range: NSMakeRange(0, originStrG.length)];
        
        
        [attrStrG insertAttributedString:attrStrAttG atIndex:0];  //NSTextAttachment占用一个字符长度，插入后原字符串长度增加1
        
        _gfzpLabel.attributedText = attrStrG;
        
        //闪电发货
        _sdfhLabel = [[UILabel alloc] initWithFrame:CGRectOf([self.ubo fx:UB_RIGHT/3.0f fy:UB_TOP oy:kHZGoodsDetailLabelHeight*2],
                                                                [self.ubo fw:UB_WIDTH/3.0f oh:kHZGoodsDetailLabelHeight])];
        _sdfhLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_sdfhLabel];
        
        NSString *originStrS = @" 24h闪电发货";
        NSTextAttachment *textAttachmentS = [[NSTextAttachment alloc] init];
        textAttachmentS.image = [UIImage imageNamed:kImageDeliveryBackGoods];  //设置图片源
        textAttachmentS.bounds = CGRectOf([self.gfzpLabel.ubo fx:UB_LEFT fy:UB_TOP py:-8],
                                          [self.gfzpLabel.ubo ow:15 oh:16]);          //设置图片位置和大小
        NSAttributedString *attrStrAttS = [NSAttributedString attributedStringWithAttachment:textAttachmentS];
        
        
        NSMutableAttributedString *attrStrS = [[NSMutableAttributedString alloc] initWithString:originStrS];
        
        [attrStrS addAttribute:NSFontAttributeName value:kHZFont_Tag_M range: NSMakeRange(0, originStrS.length)];
        [attrStrS addAttribute:NSForegroundColorAttributeName value:HZ_MALL_TEXT_M_LIGHTGRAY_COLOR range: NSMakeRange(0, originStrS.length)];
        
        
        [attrStrS insertAttributedString:attrStrAttS atIndex:0];  //NSTextAttachment占用一个字符长度，插入后原字符串长度增加1
        
        _sdfhLabel.attributedText = attrStrS;
        
        //无忧换货
        _wythLabel = [[UILabel alloc] initWithFrame:CGRectOf([self.ubo fx:UB_RIGHT*2/3.0f fy:UB_TOP oy:kHZGoodsDetailLabelHeight*2],
                                                             [self.ubo fw:UB_WIDTH/3.0f oh:kHZGoodsDetailLabelHeight])];
        _wythLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_wythLabel];
        
        NSString *originStrW = @" 15天无忧退货";
        NSTextAttachment *textAttachmentW = [[NSTextAttachment alloc] init];
        textAttachmentW.image = [UIImage imageNamed:kImageDeliveryShan];  //设置图片源
        textAttachmentW.bounds = CGRectOf([self.gfzpLabel.ubo fx:UB_LEFT fy:UB_TOP py:-8],
                                          [self.gfzpLabel.ubo ow:15 oh:16]);          //设置图片位置和大小
        NSAttributedString *attrStrAttW = [NSAttributedString attributedStringWithAttachment:textAttachmentW];
        
        
        NSMutableAttributedString *attrStrW = [[NSMutableAttributedString alloc] initWithString:originStrW];
        
        [attrStrW addAttribute:NSFontAttributeName value:kHZFont_Tag_M range: NSMakeRange(0, originStrW.length)];
        [attrStrW addAttribute:NSForegroundColorAttributeName value:HZ_MALL_TEXT_M_LIGHTGRAY_COLOR range: NSMakeRange(0, originStrW.length)];
        
        
        [attrStrW insertAttributedString:attrStrAttW atIndex:0];  //NSTextAttachment占用一个字符长度，插入后原字符串长度增加1
        
        _wythLabel.attributedText = attrStrW;
        
    }
    return self;
}


#pragma mark 点击咨询客服按钮
- (void)connectProductDetailsService{
    if (self.targetCallerService) {
        [self.targetCallerService call];
    }
    
}

@end
